package org.example.myframework.frame.common.tool;


import org.slf4j.Logger;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * future 异步封装
 */
public class CompletableFutureUtils {

    public static <T> T getResult(Future<T> future, long timeout, TimeUnit timeUnit, T defaultValue, Logger logger) {
        try {
            // 获取异步的返回结果
            return future.get(timeout, timeUnit);
        } catch (Exception e) {
            logger.error("CompletableFutureUtils.getResult.error:{}", e.getMessage(), e);
            return defaultValue;
        }
    }

}
